package com.objecteffects.template.util.logger;

import java.lang.reflect.Field;

import com.google.inject.MembersInjector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class Slf4jMembersInjector<T> implements MembersInjector<T> {
    private final Field field;
    private final Logger logger;

    Slf4jMembersInjector(final Field aField) {
        this.field = aField;
        this.logger = LoggerFactory.getLogger(this.field.getDeclaringClass());
        this.field.setAccessible(true);
    }

    @Override
    public void injectMembers(final T anArg0) {
        try {
            this.field.set(anArg0, this.logger);
        }
        catch (final IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
